package com.maila.xiaoaoschool.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.api.LoginApi;
import com.maila.xiaoaoschool.api.ShopApi;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.maila.xiaoaoschool.util.MD5;
import com.maila.xiaoaoschool.widget.gridpasswordview.GridPasswordView;
import com.maila.xiaoaoschool.widget.gridpasswordview.imebugfixer.ImeDelBugFixedEditText;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 提现
 * Created by Administrator on 2017/10/27.
 */

public class WithdrawActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.login_header)
    AutoLinearLayout loginHeader;
    @BindView(R.id.et_money)
    EditText etMoney;
    @BindView(R.id.tv_total_money)
    TextView tvTotalMoney;
    @BindView(R.id.tv_getall)
    TextView tvGetall;
    @BindView(R.id.btn_rechange)
    Button btnRechange;



    private String userKey;
//    private AccountRaply accountRaply;
    double account;
    private PopupWindow popupWindow;
    double replyaccount;//余额
    private int payType=1;
    private int hasbindali=0;
    private int hasbindwx=0;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdraw);
        ButterKnife.bind(this);


    }

    @OnClick({R.id.white_return_iv, R.id.tv_getall, R.id.btn_rechange})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.white_return_iv:
                finish();
                break;
            case R.id.tv_getall:
                break;
            case R.id.btn_rechange:
                break;
        }
    }

    private void showPassWordPopupWindow() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.password_popupwindow, null);
        View mParentView = LayoutInflater.from(this).inflate(R.layout.activity_withdraw, null);
        TextView commodity_price_tv = (TextView) contentView.findViewById(R.id.commodity_price_tv);
        TextView tv_balance = (TextView) contentView.findViewById(R.id.tv_balance);
        ImageView iv_dismiss = (ImageView) contentView.findViewById(R.id.iv_dismiss);
        final GridPasswordView pswView = (GridPasswordView) contentView.findViewById(R.id.pswView);
        ImeDelBugFixedEditText mInputView=pswView.getmInputView();
        mInputView.setFocusable(true);
        mInputView.setFocusableInTouchMode(true);
        mInputView.requestFocus();
        InputMethodManager inputManager =
                (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(mInputView, InputMethodManager.RESULT_SHOWN);
        inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        tv_balance.setText("提现金额");
        commodity_price_tv.setText("¥" + etMoney.getText().toString());
        iv_dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
        pswView.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
            @Override
            public void onTextChanged(final String psw) {
                if (psw.length() == 6) {
                    if(payType==1){

                        new ShopApi(WithdrawActivity.this, new VolleyInterface() {
                            @Override
                            public void onSuccess(String result) {

                            }

                            @Override
                            public void onError(VolleyError error) {

                            }
                        }).withdraw(etMoney.getText().toString(),MD5.md5(pswView.getPassWord()));
                    }else {

                    }

                }
            }

            @Override
            public void onInputFinish(String psw) {

            }
        });
        popupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
        popupWindow.setTouchable(true);
        popupWindow.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return false;
            }
        });
        popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.popupwindow_shape));
        popupWindow.showAtLocation(mParentView, Gravity.NO_GRAVITY, 0, 0);
        popupWindow.setOutsideTouchable(true);
        pswView.forceInputViewGetFocus();
    }

}
